/*******************************************************************************
 * Copyright (c) 2011 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package com.takaharabooks.mhp3rd;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.Cursor;
import android.database.SQLException;

public class DB_ItemList extends DB_Base
{
	//**********************定数定義**********************
	//***** 数値
	// Version
	// 2011/02/21	Ver.4
	// 2011/03/25	Ver.5
	// 2011/03/25	Ver.7
	public static final int DB_VER = 7;
	//***** 文字列
	// DB名
	public static final String	DB_NAME = "ItemList.db";
	// テーブル名
	public static final String	DB_ITEMLIST_TBL_NAME = "tb_itemlist";
	public static final String	DB_MIXLIST_TBL_NAME = "tb_mixlist";
	// 列名
	public static final String	DB_COL_ITEMLIST_ID = "itemlist_id";
	public static final String	DB_COL_ITEMLIST_MAIN_CATEGORY_ID = "itemlist_main_category_id";
	public static final String	DB_COL_ITEMLIST_SUB_CATEGORY_ID = "itemlist_sub_category_id";
	public static final String	DB_COL_ITEMLIST_NAME = "itemlist_name";
	public static final String	DB_COL_ITEMLIST_RARE = "itemlist_rare";
	public static final String	DB_COL_ITEMLIST_HAVE = "itemlist_have";
	public static final String	DB_COL_ITEMLIST_BUY_PRICE = "itemlist_buy_price";
	public static final String	DB_COL_ITEMLIST_SALE_PRICE = "itemlist_sale_price";
	public static final String	DB_COL_ITEMLIST_EFFECT = "itemlist_effect";	
	public static final String	DB_COL_ITEMLIST_GET_ITEM_NUM = "itemlist_get_item_num";	
	public static final String	DB_COL_ITEMLIST_GET_POINT = "itemlist_get_point";	
	public static final String	DB_COL_ITEMLIST_GET_RANK = "itemlist_get_rank";	
	public static final String	DB_COL_MIXLIST_NO = "mixlist_no";
	public static final String	DB_COL_MIXLIST_ITEM_ID = "mixlist_item_id";
	public static final String	DB_COL_MIXLIST_ITEM_MIX_A = "mixlist_mix_a";
	public static final String	DB_COL_MIXLIST_ITEM_MIX_B = "mixlist_mix_b";
	public static final String	DB_COL_MIXLIST_RATE = "mixlist_rate";
	public static final String	DB_COL_MIXLIST_NUM = "mixlist_num";
	public static final String	DB_COL_MIXLIST_DESC = "mixlist_desc";
	public static final String	DB_COL_MIXLIST_SUB_CATEGORY = "mixlist_sub_category";
	// メインカテゴリ
	public static final int MAIN_CATEGORY_ITEM	= 1;
	public static final int MAIN_CATEGORY_MATERIAL	= 2;
	public static final int MAIN_CATEGORY_MIX	= 3;
	//**********************定数定義**********************

    // 設定情報
    //public Preferences_Setting m_csSetting;
	// アップデートフラグ
	public boolean m_bUpdateFlag = false; 
	
	// アイテムリスト
	private int m_nItemMainCategory[];
	private int m_nItemSubCategory[];
	private String m_strItemName[];
	private int m_nItemRare[];
	private int m_nItemMaxHand[];
	private int m_nItemBuyPrice[];
	private int m_nItemSalePrice[];
	private String m_strItemEffect[];
	private int m_nItemGetNum[];
	private String m_strItemGetPoint[];
	private String m_strItemGetRank[];
	
	// 調合リスト
	private int m_nMixListNum;
	private int m_nMixItemNo[];
	private String m_strMixItemName[];
	private String m_strMixItemNameA[];
	private String m_strMixItemNameB[];
	private int m_nMixItemRate[];
	private int m_nMixItemNum[];
	private String m_strMixItemDesc[];
		
	// コンストラクタ
	public DB_ItemList(Context context) {
		super(context, DB_NAME, DB_VER);
		m_csContext = context;
	}
	
	// ＤＢからデータ取得して内部でセット
	public boolean StartDB()
	{
		// 笛リストをセット
		SetDBForItemList(1, 1);
        
        return true;
	}
	
	// ＤＢをセットしなおします
	public boolean ResetDB(int nMainCategory, int nSubCategory)
	{
		if(nMainCategory == MAIN_CATEGORY_ITEM || nMainCategory == MAIN_CATEGORY_MATERIAL){
			SetDBForItemList(nMainCategory, nSubCategory);
		}else if(nMainCategory == MAIN_CATEGORY_MIX){
			SetDBForMixList(nMainCategory, nSubCategory);
		}
		
		return true;
	}
	
	public boolean IsEachCategory(int nMainCategory, int nSubCategory)
	{
		int nCategoryNum = 0;
		// アイテムリスト
		if(nMainCategory == MAIN_CATEGORY_ITEM){
			nCategoryNum = m_stStrItemCategory.length;
		}
		// 素材リスト
		else if(nMainCategory == MAIN_CATEGORY_MATERIAL){
			nCategoryNum = m_stStrMaterialCategory.length;
		}
		// 調合リスト
		else{
			nCategoryNum = m_stStrMixListCategory.length;
		}
		return (nSubCategory <= nCategoryNum);
	}
	
	/*****************************************
	 *  絞込みのデータを取得
	 ****************************************/
    public boolean SetDBForItemList(int nMainCategory, int nSubCategory)
    {
		Cursor csCur;
		// ＤＢからデータの取得
		// アイテム（道具or素材）リストを取得
		try{
			String strQueryForWhere = String.format("where %s ", 
					DB_COL_ITEMLIST_MAIN_CATEGORY_ID + " = " + nMainCategory
			);
			if( IsEachCategory(nMainCategory, nSubCategory) ){
				strQueryForWhere += String.format("and %s ",
						DB_COL_ITEMLIST_SUB_CATEGORY_ID + " = " + nSubCategory
				);
			}
			String strQuery = String.format( "select Distinct * from %s " + strQueryForWhere,
					DB_ITEMLIST_TBL_NAME
			);
	    	csCur = readDB(strQuery);			
		}catch(Exception e){
			// 例外時は何もしない
			return false;
		}
		
		int nItemListNum = csCur.getCount();
		m_nItemMainCategory = new int[nItemListNum];
		m_nItemSubCategory = new int[nItemListNum];
		m_strItemName = new String[nItemListNum];
		m_nItemRare = new int[nItemListNum];
		m_nItemMaxHand = new int[nItemListNum];
		m_nItemBuyPrice = new int[nItemListNum];
		m_nItemSalePrice = new int[nItemListNum];
		m_strItemEffect = new String[nItemListNum];
		m_nItemGetNum = new int[nItemListNum];
		m_strItemGetPoint = new String[nItemListNum];
		m_strItemGetRank = new String[nItemListNum];
    	
    	// カーソルを使ってメンバ変数にデータをセット
        csCur.moveToFirst();
        for(int nIndex=0; nIndex<nItemListNum; nIndex++){
        	m_nItemMainCategory[nIndex] = csCur.getInt(1);
        	m_nItemSubCategory[nIndex] = csCur.getInt(2);
        	m_strItemName[nIndex] = csCur.getString(3);
        	m_nItemRare[nIndex] = csCur.getInt(4);
        	m_nItemMaxHand[nIndex] = csCur.getInt(5);
        	m_nItemBuyPrice[nIndex] = csCur.getInt(6);
        	m_nItemSalePrice[nIndex] = csCur.getInt(7);
        	m_strItemEffect[nIndex] = csCur.getString(8);
        	m_nItemGetNum[nIndex] = csCur.getInt(9);
        	m_strItemGetPoint[nIndex] = csCur.getString(10);
        	m_strItemGetRank[nIndex] = csCur.getString(11);
        	csCur.moveToNext();
        }
        csCur.close();

        return true;
    }

	/*****************************************
	 *  絞込みのデータを取得
	 ****************************************/
    public boolean SetDBForMonsterMaterialList(String strMonsterName)
    {
		Cursor csCur;
		// ＤＢからデータの取得
		// アイテム（道具or素材）リストを取得
		try{
			String strQuery = String.format( "select Distinct * from %s where %s",
					DB_ITEMLIST_TBL_NAME,
					DB_COL_ITEMLIST_EFFECT + " like \'%" + strMonsterName + "%\'"
			);
	    	csCur = readDB(strQuery);			
		}catch(Exception e){
			// 例外時は何もしない
			return false;
		}
		
		
		int nItemListNum = csCur.getCount();
		m_nItemMainCategory = new int[nItemListNum];
		m_nItemSubCategory = new int[nItemListNum];
		m_strItemName = new String[nItemListNum];
		m_nItemRare = new int[nItemListNum];
		m_nItemMaxHand = new int[nItemListNum];
		m_nItemBuyPrice = new int[nItemListNum];
		m_nItemSalePrice = new int[nItemListNum];
		m_strItemEffect = new String[nItemListNum];
		m_nItemGetNum = new int[nItemListNum];
		m_strItemGetPoint = new String[nItemListNum];
		m_strItemGetRank = new String[nItemListNum];
    	
    	// カーソルを使ってメンバ変数にデータをセット
        csCur.moveToFirst();
        for(int nIndex=0; nIndex<nItemListNum; nIndex++){
        	m_nItemMainCategory[nIndex] = csCur.getInt(1);
        	m_nItemSubCategory[nIndex] = csCur.getInt(2);
        	m_strItemName[nIndex] = csCur.getString(3);
        	m_nItemRare[nIndex] = csCur.getInt(4);
        	m_nItemMaxHand[nIndex] = csCur.getInt(5);
        	m_nItemBuyPrice[nIndex] = csCur.getInt(6);
        	m_nItemSalePrice[nIndex] = csCur.getInt(7);
        	m_strItemEffect[nIndex] = csCur.getString(8);
        	m_nItemGetNum[nIndex] = csCur.getInt(9);
        	m_strItemGetPoint[nIndex] = csCur.getString(10);
        	m_strItemGetRank[nIndex] = csCur.getString(11);
        	csCur.moveToNext();
        }
        csCur.close();

        return true;
    }
    
	/*****************************************
	 *  調合リストのデータを取得
	 ****************************************/
    public boolean SetDBForMixList(int nMainCategory, int nSubCategory)
    {
		Cursor csCur;
		// ＤＢからデータの取得
		// アイテム（道具or素材）リストを取得
		try{
			String strWhere = String.format("%s = %s", 
					DB_COL_ITEMLIST_ID,
					DB_COL_MIXLIST_ITEM_ID
			);
			String strWhereA = String.format("%s = %s", 
					DB_COL_ITEMLIST_ID,
					DB_COL_MIXLIST_ITEM_MIX_A
			);
			String strWhereB = String.format("%s = %s", 
					DB_COL_ITEMLIST_ID,
					DB_COL_MIXLIST_ITEM_MIX_B
			);
			String strQueryForWhere = "";
			if( IsEachCategory(nMainCategory, nSubCategory) ){
				strQueryForWhere += String.format(" and %s ",
						DB_COL_MIXLIST_SUB_CATEGORY + " = " + nSubCategory
				);
			}
			String strQuery = String.format(
					"select Distinct %s, A.%s, B.%s, C.%s, %s, %s, A.%s from %s, %s A, %s B, %s C" +
					" where A.%s and B.%s and C.%s %s",
					DB_COL_MIXLIST_NO,
					DB_COL_ITEMLIST_NAME,
					DB_COL_ITEMLIST_NAME,
					DB_COL_ITEMLIST_NAME,
					DB_COL_MIXLIST_RATE,
					DB_COL_MIXLIST_NUM,
					DB_COL_ITEMLIST_EFFECT,
					DB_MIXLIST_TBL_NAME,
					DB_ITEMLIST_TBL_NAME,
					DB_ITEMLIST_TBL_NAME,
					DB_ITEMLIST_TBL_NAME,
					strWhere, strWhereA, strWhereB, strQueryForWhere
//					DB_COL_MIXLIST_EFFECT + " like \'%" + strMonsterName + "%\'"
			);
	    	csCur = readDB(strQuery);			
		}catch(Exception e){
			// 例外時は何もしない
			return false;
		}
		
		m_nMixListNum = csCur.getCount();
		m_nMixItemNo = new int[m_nMixListNum];
		m_strMixItemName = new String[m_nMixListNum];
		m_strMixItemNameA = new String[m_nMixListNum];
		m_strMixItemNameB = new String[m_nMixListNum];
		m_nMixItemRate = new int[m_nMixListNum];
		m_nMixItemNum = new int[m_nMixListNum];
		m_strMixItemDesc = new String[m_nMixListNum];
		
    	// カーソルを使ってメンバ変数にデータをセット
        csCur.moveToFirst();
        for(int nIndex=0; nIndex<m_nMixListNum; nIndex++){
        	m_nMixItemNo[nIndex] = csCur.getInt(0);
        	m_strMixItemName[nIndex] = csCur.getString(1);
        	m_strMixItemNameA[nIndex] = csCur.getString(2);
        	m_strMixItemNameB[nIndex] = csCur.getString(3);
        	m_nMixItemRate[nIndex] = csCur.getInt(4);
        	m_nMixItemNum[nIndex] = csCur.getInt(5);
        	m_strMixItemDesc[nIndex] = csCur.getString(6);
        	csCur.moveToNext();
        }
        csCur.close();
		
		return true;
    }
    
	/*****************************************
	 *  データ数を取得
	 ****************************************/
    public int GetItemListNum(int nMainCategory){
    	try{
	    	if( nMainCategory == MAIN_CATEGORY_ITEM ||
	    			nMainCategory == MAIN_CATEGORY_MATERIAL){
	    		return m_strItemName.length;
	    	}else{
	    		return GetMixListNum();
	    	}
    	}catch(Exception e){
    		return 0;
    	}
    }
	
	/*****************************************
	 *  メインカテゴリＩＤを取得
	 ****************************************/
    public int GetMainCategoryID(int nIndex){
    	return m_nItemMainCategory[nIndex];
    }
	
	/*****************************************
	 *  サブカテゴリＩＤを取得
	 ****************************************/
    public int GetSubCategoryID(int nIndex){
    	return m_nItemSubCategory[nIndex];
    }
	
	/*****************************************
	 *  アイテム名（文字列）を取得【アイテムor素材】
	 ****************************************/
	public String GetItemNameStr(int nIndex)
	{
		// アイテムリストを返す
		return m_strItemName[nIndex];
	}

	/*****************************************
	 *  レア（数値）を取得
	 ****************************************/
    public int GetItemRareNum(int nIndex){
    	return m_nItemRare[nIndex];
    }
	
	/*****************************************
	 *  最大所持数（数値）を取得
	 ****************************************/
    public int GetItemMaxHandNum(int nIndex){
    	return m_nItemMaxHand[nIndex];
    }
	
	/*****************************************
	 *  買値（数値）を取得
	 ****************************************/
    public int GetItemBuyPriceNum(int nIndex){
    	return m_nItemBuyPrice[nIndex];
    }
	
	/*****************************************
	 *  売値（数値）を取得
	 ****************************************/
    public int GetItemSalePriceNum(int nIndex){
    	return m_nItemSalePrice[nIndex];
    }
	
	/*****************************************
	 *  効果（文字列）を取得
	 ****************************************/
	public String GetItemEffectStr(int nIndex)
	{
		return m_strItemEffect[nIndex];
	}
	
	/*****************************************
	 *  アイテム取得個数（数値）を取得
	 ****************************************/
	public int GetItemGetNum(int nIndex)
	{
    	return m_nItemGetNum[nIndex];
	}

	/*****************************************
	 *  ｱｲﾃﾑ取得場所（文字列）を取得
	 ****************************************/
	public String GetItemGetPointStr(int nIndex)
	{
		return m_strItemGetPoint[nIndex];
	}

	/*****************************************
	 *  ｱｲﾃﾑ取得ランク（文字列）を取得
	 ****************************************/
	public String GetItemGetRankStr(int nIndex)
	{
		return m_strItemGetRank[nIndex];
	}

	/*****************************************
	 *  ｱｲﾃﾑ種別数を取得
	 ****************************************/
	public int GetKindItemNum(int nMainCategoryNo)
	{
		if(nMainCategoryNo == MAIN_CATEGORY_ITEM){
			return m_stStrItemCategory.length;
		}else if(nMainCategoryNo == MAIN_CATEGORY_MATERIAL){
			return m_stStrMaterialCategory.length;			
		}else{
			return m_stStrMixListCategory.length;			
		}
	}

	/*****************************************
	 *  ｱｲﾃﾑ種別（文字列）を取得
	 ****************************************/
	public String GetKindItemStr(int nIndex, int nMainCategoryNo)
	{
		if(nMainCategoryNo == MAIN_CATEGORY_ITEM){
			return m_stStrItemCategory[nIndex];
		}else if(nMainCategoryNo == MAIN_CATEGORY_MATERIAL){
			return m_stStrMaterialCategory[nIndex];
		}else if(nMainCategoryNo == MAIN_CATEGORY_MIX){
			return m_stStrMixListCategory[nIndex];
		}
		return "";
	}

	/*****************************************
	 *  調合リスト数を取得
	 ****************************************/
	public int GetMixListNum(){
		return m_nMixListNum;
	}

	/*****************************************
	 *  調合NO.を取得
	 ****************************************/
	public int GetMixItemNo(int nIndex){
		return m_nMixItemNo[nIndex];
	}

	/*****************************************
	 *  調合アイテム名を取得
	 ****************************************/
	public String GetMixItemName(int nIndex){
		return m_strMixItemName[nIndex];
	}

	/*****************************************
	 *  調合用アイテム名①を取得
	 ****************************************/
	public String GetMixItemNameA(int nIndex){
		return m_strMixItemNameA[nIndex];
	}

	/*****************************************
	 *  調合用アイテム名②を取得
	 ****************************************/
	public String GetMixItemNameB(int nIndex){
		return m_strMixItemNameB[nIndex];
	}

	/*****************************************
	 *  調合率を取得
	 ****************************************/
	public int GetMixItemRate(int nIndex){
		return m_nMixItemRate[nIndex];
	}

	/*****************************************
	 *  調合最大数を取得
	 ****************************************/
	public int GetMixItemNum(int nIndex){
		return m_nMixItemNum[nIndex];
	}

	/*****************************************
	 *  調合用アイテムの説明を取得
	 ****************************************/
	public String GetMixItemDesc(int nIndex){
		return m_strMixItemDesc[nIndex];
	}

    //データベースオブジェクトを取得する（データベースにアクセスするとDBがない場合は作成される。）  
	public void InitDB(){
		InitDBBase();//DB_Base
		StartDB();
	}

	// @Override onCreate
	@Override
	public void onCreate(SQLiteDatabase db)
	{
		InitAllTbl(db);
    }

	// @Override onUpgrade
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
	{
		// いつでも？
		{
			DropAllTbl(db, oldVersion);
			InitAllTbl(db);
		}
		
		////////////////////////////
		// 全バージョン共通処理

		m_bUpdateFlag = true;
	}
	
	// ＤＢをすべて破棄します
	public void DropAllTbl(SQLiteDatabase db, int oldVersion)
	{
        String sql = "";  
        // アイテムリストテーブル削除
        try {
	        sql += "drop table " + DB_ITEMLIST_TBL_NAME;
	        db.execSQL(sql);
    	}catch(SQLException e){
    	}
        // 調合リストテーブル削除
        try {
            sql = "";  
	        sql += "drop table " + DB_MIXLIST_TBL_NAME;
	        db.execSQL(sql);
    	}catch(SQLException e){
    	}
	}
	
	// ＤＢをすべて作成します
	public void InitAllTbl(SQLiteDatabase db)
	{
		CreateItemListTbl(db);
		CreateMixListTbl(db);
		InsertDBNoneItemListData(db);
	}
	
	/*****************************************
	 *  アイテムテーブルを作成
	 ****************************************/
	public void CreateItemListTbl(SQLiteDatabase db)
	{
		// DBクリエイト
        String sql = String.format(
        		"create table %s (%s integer primary key, %s integer, %s integer, %s text not null," + 
        						 "%s integer, %s integer, %s integer, %s integer, %s text not null," +
        						 "%s integer, %s text not null, %s text not null)",
        		DB_ITEMLIST_TBL_NAME,
        		DB_COL_ITEMLIST_ID,
        		DB_COL_ITEMLIST_MAIN_CATEGORY_ID,
        		DB_COL_ITEMLIST_SUB_CATEGORY_ID,
        		DB_COL_ITEMLIST_NAME,
        		DB_COL_ITEMLIST_RARE,
        		DB_COL_ITEMLIST_HAVE,
        		DB_COL_ITEMLIST_BUY_PRICE,
        		DB_COL_ITEMLIST_SALE_PRICE,
        		DB_COL_ITEMLIST_EFFECT,
        		DB_COL_ITEMLIST_GET_ITEM_NUM,
        		DB_COL_ITEMLIST_GET_POINT,
        		DB_COL_ITEMLIST_GET_RANK
        		);
        db.execSQL(sql);

        // データ挿入（アイテム＆素材）
        InsertDBItemListData(db);
        InsertDBMaterialListData(db);
	}
	
	/*****************************************
	 *  調合テーブルを作成
	 ****************************************/
	public void CreateMixListTbl(SQLiteDatabase db)
	{
		// DBクリエイト
        String sql = String.format(
        		"create table %s (%s integer primary key, %s integer, %s integer, %s integer," + 
        						 "%s integer, %s integer, %s integer)",
        		DB_MIXLIST_TBL_NAME,
        		DB_COL_MIXLIST_NO,
        		DB_COL_MIXLIST_ITEM_ID,
        		DB_COL_MIXLIST_ITEM_MIX_A,
        		DB_COL_MIXLIST_ITEM_MIX_B,
        		DB_COL_MIXLIST_RATE,
        		DB_COL_MIXLIST_NUM,
        		DB_COL_MIXLIST_SUB_CATEGORY
        		);
        db.execSQL(sql);

        // データ挿入（アイテム＆素材）
        InsertDBMixListData(db);
	}
	
	/*****************************************
	 *  アイテムリストにアイテムデータを追加します
	 *  [IN.] db				ＤＢアクセスクラス
	 *  [IN.] strData			追加するデータ
	 *  [IN.] nMainCategoryNo	メインカテゴリＮｏ
	 *  [IN.] nStartIndex		テーブルNo.の開始位置
	 ****************************************/
	private void InsertDBItemListData( SQLiteDatabase db )
	{
		String sql = "";
		
        int nNo = 0;
        int nHave = 0;
        int nBuyPrice = 0;
        int nSalePrice = 0;
        for(int nIndex=0; nIndex<DB_DefineData_Item.m_stStrItemDesc.length; nIndex++)
        {
        	nNo = nIndex + 1;
        	// 所持数
        	if(0 < DB_DefineData_Item.m_stStrItemDesc[nIndex][3].length()){
        		nHave = Integer.parseInt(DB_DefineData_Item.m_stStrItemDesc[nIndex][3]);
        	}
        	// 購入額
        	if(0 < DB_DefineData_Item.m_stStrItemDesc[nIndex][4].length()){
        		nBuyPrice = Integer.parseInt(DB_DefineData_Item.m_stStrItemDesc[nIndex][4]);
        	}
        	// 売却額
        	if(0 < DB_DefineData_Item.m_stStrItemDesc[nIndex][5].length()){
        		nSalePrice = Integer.parseInt(DB_DefineData_Item.m_stStrItemDesc[nIndex][5]);
        	}
        	sql = String.format(
        			"insert into %s values(%d, %d, %d, \'%s\', %d,  %d, %d, %d, \'%s\', 0, \'\', \'\')",
        			DB_ITEMLIST_TBL_NAME,
        			nNo,
        			MAIN_CATEGORY_ITEM,
        			Integer.parseInt(DB_DefineData_Item.m_stStrItemDesc[nIndex][1]),
        			DB_DefineData_Item.m_stStrItemDesc[nIndex][0],
        			Integer.parseInt(DB_DefineData_Item.m_stStrItemDesc[nIndex][2]),
        			nHave,
        			nBuyPrice,
        			nSalePrice,
        			DB_DefineData_Item.m_stStrItemDesc[nIndex][6]
        	);
            db.execSQL(sql);
        }		
	}
		
	/*****************************************
	 *  アイテムリストに素材データを追加します
	 *  [IN.] db				ＤＢアクセスクラス
	 *  [IN.] strData			追加するデータ
	 *  [IN.] nMainCategoryNo	メインカテゴリＮｏ
	 *  [IN.] nStartIndex		テーブルNo.の開始位置
	 ****************************************/
	private void InsertDBMaterialListData( SQLiteDatabase db )
	{
		String sql = "";
		
        int nNo = 0;
        int nHave = 0;
        int nBuyPrice = 0;
        int nSalePrice = 0;
        for(int nIndex=0; nIndex<DB_DefineData_Item.m_stStrMaterialDesc.length; nIndex++)
        {
        	nNo = nIndex + DB_DefineData_Item.m_stStrItemDesc.length + 1;
        	//　所持数
        	if(0 < DB_DefineData_Item.m_stStrMaterialDesc[nIndex][3].length()){
        		nHave = Integer.parseInt(DB_DefineData_Item.m_stStrMaterialDesc[nIndex][3]);
        	}
        	// 購入額
        	if(0 < DB_DefineData_Item.m_stStrMaterialDesc[nIndex][4].length()){
        		nBuyPrice = Integer.parseInt(DB_DefineData_Item.m_stStrMaterialDesc[nIndex][4]);
        	}
        	// 売却額
        	if(0 < DB_DefineData_Item.m_stStrMaterialDesc[nIndex][5].length()){
        		nSalePrice = Integer.parseInt(DB_DefineData_Item.m_stStrMaterialDesc[nIndex][5]);
        	}
        	sql = String.format(
        			"insert into %s values(%d, %d, %d, \'%s\', %d,  %d, %d, %d, \'%s\', %d, \'%s\', \'%s\')",
        			DB_ITEMLIST_TBL_NAME,
        			nNo,
        			MAIN_CATEGORY_MATERIAL,
        			Integer.parseInt(DB_DefineData_Item.m_stStrMaterialDesc[nIndex][1]),
        			DB_DefineData_Item.m_stStrMaterialDesc[nIndex][0],
        			Integer.parseInt(DB_DefineData_Item.m_stStrMaterialDesc[nIndex][2]),
        			nHave,
        			nBuyPrice,
        			nSalePrice,
        			DB_DefineData_Item.m_stStrMaterialDesc[nIndex][9],
        			Integer.parseInt(DB_DefineData_Item.m_stStrMaterialDesc[nIndex][6]),
        			DB_DefineData_Item.m_stStrMaterialDesc[nIndex][7],
        			DB_DefineData_Item.m_stStrMaterialDesc[nIndex][8]
        	);
            db.execSQL(sql);
        }		
	}
		
	/*****************************************
	 *  支給品アイテムリストにアイテムデータを追加します
	 *  [IN.] db				ＤＢアクセスクラス
	 ****************************************/
	private void InsertDBNoneItemListData( SQLiteDatabase db )
	{
		String sql = "";
		
        int nNo = 0;
        int nHave = 0;
        int nBuyPrice = 0;
        int nSalePrice = 0;
        for(int nIndex=0; nIndex<DB_DefineData_Item.m_stStrNoneItemList.length; nIndex++)
        {
        	nNo = nIndex + 1 + 231 + 401;
        	// 所持数
        	if(0 < DB_DefineData_Item.m_stStrNoneItemList[nIndex][3].length()){
        		nHave = Integer.parseInt(DB_DefineData_Item.m_stStrNoneItemList[nIndex][3]);
        	}
        	// 購入額
        	if(0 < DB_DefineData_Item.m_stStrNoneItemList[nIndex][4].length()){
        		nBuyPrice = Integer.parseInt(DB_DefineData_Item.m_stStrNoneItemList[nIndex][4]);
        	}
        	// 売却額
        	if(0 < DB_DefineData_Item.m_stStrNoneItemList[nIndex][5].length()){
        		nSalePrice = Integer.parseInt(DB_DefineData_Item.m_stStrNoneItemList[nIndex][5]);
        	}
        	sql = String.format(
        			"insert into %s values(%d, %d, %d, \'%s\', %d,  %d, %d, %d, \'%s\', 0, \'\', \'\')",
        			DB_ITEMLIST_TBL_NAME,
        			nNo,
        			MAIN_CATEGORY_ITEM,
        			Integer.parseInt(DB_DefineData_Item.m_stStrNoneItemList[nIndex][1]),
        			DB_DefineData_Item.m_stStrNoneItemList[nIndex][0],
        			Integer.parseInt(DB_DefineData_Item.m_stStrNoneItemList[nIndex][2]),
        			nHave,
        			nBuyPrice,
        			nSalePrice,
        			DB_DefineData_Item.m_stStrNoneItemList[nIndex][6]
        	);
            db.execSQL(sql);
        }		
	}
		
	/*****************************************
	 *  調合リストに素材データを追加します
	 *  [IN.] db				ＤＢアクセスクラス
	 ****************************************/
	private void InsertDBMixListData( SQLiteDatabase db )
	{
		String sql = "";
		
        int nNo = 0;
        for(int nIndex=0; nIndex<m_stnMixList.length; nIndex++)
        {
        	nNo = nIndex + 1;
        	sql = String.format(
        			"insert into %s values(%d, %d, %d, %d,  %d, %d, %d)",
        			DB_MIXLIST_TBL_NAME,
        			nNo,
        			m_stnMixList[nIndex][0],
        			m_stnMixList[nIndex][1],
        			m_stnMixList[nIndex][2],
        			m_stnMixList[nIndex][3],
        			m_stnMixList[nIndex][4],
        			m_stnMixList[nIndex][5]
        	);
            db.execSQL(sql);
        }		
	}
		
	//////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////
	// ＤＢ上に入れるデフォルトの値
	
	// アイテム－カテゴリ
	private String[] m_stStrItemCategory = {
			// 道具
			"書物系",		// 1
			"薬系",			// 2
			"護符",			// 3
			"食料系",		// 4
			"道具類",		// 5
			"爆弾系",		// 6
			"採取系",		// 7
			"笛系",			// 8
			"植物系",		// 9
			// 鉱石
			"鉱石系",		// 10
			// 魚
			"魚系"	,		// 11
			// 虫
			"虫系",			// 12
			// ボウガン弾
			"ボウガン弾",		// 13
			// 弓ビン
			"弓ビン",			// 14
			// 支給品
			"支給品"			// 15
	};
	
	
	// 素材－カテゴリ
	private String[] m_stStrMaterialCategory = {
			// 素材
			"木材",		// 1
			"骨・髄",		// 2
			"牙　",		// 3
			"爪　",		// 4
			"玉　",		// 5
			"血・体液",	// 6
			"袋・腺",		// 7
			"角　",		// 8
			"羽・翼",		// 9
			"毛・皮・膜",	// 10
			"甲・殻",		// 11
			"ヒレ",		// 12
			"針・棘",		// 13
			"顎　",		// 14
			"頭　",		// 15
			"鱗　",		// 16
			"エリマキ",	// 17
			"口　",		// 18
			"クチバシ",	// 19
			"トサカ",		// 20
			"コブ",		// 21
			"耳　",		// 22
			"破片",		// 23
			"石・ドロ・塊",	// 24
			"尻尾",		// 25
			"たまご",		// 26
			"お守り",		// 27
			"チケット"		// 28
	};
	
	// アイテム－カテゴリ
	public String[] m_stStrMixListCategory = {
			// 道具
			"薬系",			// 1
			"肉類",			// 2
			"玉・遠距離武器系",// 3
			"爆弾・罠系",		// 4
			"採取・採掘系",	// 5
			"笛系",			// 6
			"護符系",		// 7
			"弾薬",			// 8
			"ビン類"	,		// 9
	};
	
	// 調合リスト
	public int[][] m_stnMixList = {
		//　アイテムＩＤ、調合ＩＤ①、調合ＩＤ②、調合率、調合でできる数
			{	8, 102, 113,  	95,  1, 1},
			{	9,   8, 101,  	90,  1, 1},
			{  10, 113, 177,  	90,  1, 1},
			{  11,  10, 101,  	75,  1, 1},
			{  12, 103, 113,  	95,  1, 1},
			{  13, 110, 178,  	90,  1, 1},
			{  29,  11, 119,  	65,	 1, 1},
			{  30,  14, 231+40, 55,  1, 1},
			{  33, 101, 178, 	75,	 1, 1},
			{  14,  33, 119,	75,  1, 1},
			// 10
			{  26,  33, 162,	90,  1, 1},
			{  16,  33,  43,	75,  1, 1},
			{  17,  44, 231+35,	65,  1, 1},
			{  15, 101, 114,	65,  1, 1},
			{  18,  33, 123,	65,  1, 1},
			{  19,  18, 231+36,	55,  1, 1},
			{  20,  14, 123,	75,  1, 1},
			{  21,  33, 124,	65,  1, 1},
			{  22,  21, 231+36,	55,  1, 1},
			{  23,  14, 124,	75,  1, 1},
			// 20
			{  25, 111, 178,	95,  1, 1},
			{  47,  44, 111,	95,  1, 2},
			{  24, 178, 151,	95,  1, 1},
			{  46,  44, 151,	95,  1, 2},
			{  40,  39, 116,	90,  1, 2},
			{  41,  39, 115,	90,  1, 2},
			{  42,  39, 107,	90,  1, 2},
			{  53, 108, 135,	95,  1, 3},
			{  27,  53, 105,	95,  1, 3},
			{  60,  53, 106,	75,  1, 3},
			// 30
			{  61,  53, 116,	75,  1, 3},
			{  55,  53, 179,	75,  1, 3},
			{  59,  53,  57,	75,  1, 3},
			{  54, 108, 122,	95,  1, 3},
			{  62,  53, 117,	95,  1, 3},
			{  69, 104,	114,	95,  1, 4},
			{  72,  70, 104,	90,  1, 4},
			{  73,  69,  71,	75,  1, 4},
			{  74,  73, 163,	75,  1, 4},
			{  75,  72, 231+55,	75,  1, 4},
			// 40
			{  56,  69, 231+21,	75,  1, 4},
			{  76,  72, 109,	90,  1, 4},
			{  65,  64, 106,	90,  1, 4},
			{  67,  65,  66,	75,  1, 4},
			{  68,  66, 180,	90,  1, 4},
			{  91,  90, 176,	85,  1, 5},
			{  92,  90, 175,	90,  1, 5},
			{  93,  90, 174,	90,  1, 5},
			{  79, 135, 231+5,	95,  1, 5},
			{  80, 136, 231+5,	85,  1, 5},
			//50
			{  81, 138, 231+5,	75,  1, 5},
			{  83,  65, 231+3,	95,  1, 5},
			{  84,  65, 231+6,	85,  1, 5},
			{  85,  65, 231+7,	75,  1, 5},
			{  31, 177, 231+16,	90,  1, 1},
			{  32,  31, 231+17,	65,  1, 1},
			{  97,  31,  96,	65,  1, 6},
			{  98,  12,  96,	65,  1, 6},
			{  99,  19, 231+7,	55,  1, 6},
			{ 100,  22, 231+7,	55,  1, 6},
			// 60
			{ 231+401+11,  231+401+10, 116,	90,  1, 3},
			{ 231+401+12,  231+401+10, 107,	90,  1, 3},
			{ 231+401+13,  231+401+10, 115,	90,  1, 3},
			{  52,   86, 231+6,	90,  1, 3},
			{  36,   35, 231+329,100, 1, 7},
			{  38,   37, 231+329,100, 1, 7},
			{ 190,   87, 128,	95,  3, 8},
			{ 191,   87, 162,	95,  4, 8},
			{ 192,   87, 129,	90,  2, 8},
			{ 193,   88, 231+68,75,  2, 8},
			//70
			{ 194,   88, 161,	75,  3, 8},
			{ 195,   87, 127,	90,  2, 8},
			{ 196,   87, 231+16,75,  2, 8},
			{ 197,   88, 231+16,75,  2, 8},
			{ 198,   87, 114,	90,  1, 8},
			{ 199,   88, 164,	90,  1, 8},
			{ 200,   88, 165,	95,  1, 8},
			{ 201,   87, 130,	90,  1, 8},
			{ 202,   88, 231+17,75,  1, 8},
			{ 203,   88, 163,	75,  2, 8},
			// 80
			{ 204,   87, 104,	85,  2, 8},
			{ 205,   87, 158,	85,  2, 8},
			{ 207,   87, 105,	85,  2, 8},
			{ 206,   87, 179,	85,  4, 8},
			{ 208,   88, 126,	85,  1, 8},
			{ 218,   87, 102,	90,  1, 8},
			{ 219,    8,  87,	90,  1, 8},
			{ 210,   87, 116,	90,  2, 8},
			{ 211,   88, 231+78,75,  1, 8},
			{ 212,   87, 115,	90,  2, 8},
			// 90
			{ 213,   88, 231+56,75,  1, 8},
			{ 214,   87, 107,	90,  1, 8},
			{ 215,   88, 160,	75,  1, 8},
			{ 223,   87, 122,	90,  1, 8},
			{ 220,   18,  87,	75,  1, 8},
			{ 221,   21,  87,	75,  1, 8},
			{ 216,   87, 118,	90,  2, 8},
			{ 217,   88, 167,	75,  3, 8},
			{ 209,   86,  87,	90,  2, 8},
			{ 224,   86,  88,	85,  2, 9},
			// 100
			{ 227,  224, 116,	90,  2, 9},
			{ 228,  224, 115,	85,  2, 9},
			{ 229,  224, 107,	90,  2, 9},
			{ 225,  224, 114,	85,  2, 9},
			{ 226,  224, 158,	85,  2, 9},
			{ 231,  224, 122,	90,  2, 9},
			{ 230,  224, 118,	90,  2, 9},
			{  34,  107, 115,	65,  2, 1},
			{ 231+401+14,   34,  231+401+10,	65,  2, 3},
			{  63,   34,  53,	75,  2, 3},
			// 110
			{ 222,   34,  87,	90,  2, 8},
			{ 154,  138, 153,  100,  1, 3},
			{ 154,  182, 153,  100,  1, 3},
			{ 155,  143, 153,  100,  1, 3},
			{ 155,  183, 153,  100,  1, 3},
			{ 156,  146, 153,  100,  1, 3},
			{ 156,  185, 153,  100,  1, 3}
	};
}